import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
import Layout from '@/layout'
import i18n from '@/i18n/index'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/error/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [{
      path: 'home',
      name: 'Home',
      component: () => import('@/views/home/index'),
      meta: { title: i18n.t('menu.home'), icon: 'el-icon-s-home', affix: true }
    }]
  },
  // {
  //   path: '/dashboard',
  //   component: Layout,
  //   redirect: '/dashboard/index',
  //   children: [{
  //     path: 'index',
  //     name: 'DashBoard',
  //     component: () => import('@/views/dashboard/index'),
  //     meta: { title: '数据仪表盘', icon: 'el-icon-s-data' }
  //   }]
  // },
  {
    path: '/system',
    component: Layout,
    redirect: '/system/user',
    name: 'System',
    meta: { title: i18n.t('menu.system'), icon: 'el-icon-setting' },
    children: [
      {
        path: 'user',
        name: 'User',
        component: () => import('@/views/system/user/index'),
        meta: { title: i18n.t('menu.user'), icon: 'el-icon-user' }
      },
      {
        path: 'role',
        name: 'Role',
        component: () => import('@/views/system/role/index'),
        meta: { title: i18n.t('menu.role'), icon: 'el-icon-lock' }
      },
      {
        path: 'menu',
        name: 'Menu',
        component: () => import('@/views/system/menu/index'),
        meta: { title: i18n.t('menu.menu'), icon: 'el-icon-menu' }
      },
      {
        path: 'oss',
        name: 'Oss',
        component: () => import('@/views/system/oss/index'),
        meta: { title: i18n.t('menu.oss'), icon: 'el-icon-menu' }
      }
    ]
  },

  {
    path: '/pos',
    component: Layout,
    redirect: '/pos/sale',
    name: 'Pos',
    meta: { title: i18n.t('menu.saleManagement'), icon: 'el-icon-s-help' },
    children: [
      {
        path: 'category',
        name: 'Category',
        component: () => import('@/views/pos/category/index'),
        meta: { title: i18n.t('menu.category'), icon: 'el-icon-box' }
      },
      {
        path: 'oss',
        name: 'Oss',
        component: () => import('@/views/pos/oss/index'),
        meta: { title: i18n.t('menu.product'), icon: 'el-icon-wallet' }
      },
      {
        path: 'sale',
        name: 'Sale',
        component: () => import('@/views/pos/sale/index'),
        meta: { title: i18n.t('menu.sale'), icon: 'el-icon-shopping-cart-full' }
      }
    ]
  },




  {
    path: 'external-link',
    component: Layout,
    children: [
      {
        path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
        meta: { title: i18n.t('menu.vat'), icon: 'link' }
      }
    ]
  },

  
  // {
  //   path: '/page',
  //   component: Layout,
  //   redirect: '/page/index',
  //   children: [{
  //     path: 'index',
  //     name: 'Page',
  //     component: () => import('@/views/page/index'),
  //     meta: { title: '测试页', icon: 'el-icon-s-data' }
  //   }]
  // },

  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export default router
